/*!
 * \file __list_node_pri_show.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frproto_mng.h"
#include "apmtest_cunit.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{
//    frmodule_mng_init();
    return 0;
}

static int __suite_cleanup(void)
{
//    frmodule_mng_destory();
    return 0;
}


typedef struct __st_proto_priority {
    u_short us_port_start;      /* port 开始 */
    u_short us_port_end;        /* port 结束 */

    Frmodule_mng *p_module_mng;
} Frproto_priority;

void __list_node_pri_show(Frlist_node* p_st_node, char *p_outbuff, unsigned int ui_buff_size);

static void __case1(void)
{
    Frlist_node* p_st_node = NULL;
    char *p_outbuff = NULL;
    unsigned int ui_buff_size = 2048;
    Frproto_priority *p_st_proto_pri_node_data = NULL;
    Frmodule_mng *p_module_mng = NULL;

    //p_module_mng
    p_module_mng = (Frmodule_mng *)frmalloc(sizeof(Frmodule_mng));
    memset(p_module_mng, 0x00, sizeof(Frmodule_mng));

    p_module_mng->i_is_stub = FR_YES;
    p_module_mng->p_st_l7_module = (L7_module *)frmalloc(sizeof(L7_module));
    memset(p_module_mng->p_st_l7_module ,0x00, sizeof(L7_module));
    p_module_mng->p_st_l7_module->i_l7_proto = 1;
    p_module_mng->p_st_l7_module->us_l4_proto = 6;
    p_module_mng->p_st_l7_module->p_module_name = frstrdup("p_module_name");
    p_module_mng->p_st_l7_module->p_version = frstrdup("p_version");

    //p_st_proto_pri_node_data
    p_st_proto_pri_node_data = (Frproto_priority *)frmalloc(sizeof(Frproto_priority));
    memset(p_st_proto_pri_node_data, 0x00, sizeof(Frproto_priority));
    p_st_proto_pri_node_data->us_port_start = 40;
    p_st_proto_pri_node_data->us_port_end = 80;
    p_st_proto_pri_node_data->p_module_mng = p_module_mng;

    //p_st_node
    p_st_node = frlist_node_create(p_st_proto_pri_node_data);

    //p_outbuff
    p_outbuff = (char *)frmalloc(ui_buff_size);
    memset(p_outbuff, 0x00, ui_buff_size);

    __list_node_pri_show(p_st_node, p_outbuff, ui_buff_size);

//    CU_ASSERT_STRING_EQUAL(p_outbuff,"port[40-80][p_so_name]\tis_stub=YES l7_proto=1 ip_proto=(6)[tcp] module_name=[p_module_name] version=[p_version]\n");
    // frdbg("\t%s\t",p_outbuff);

    frfree(p_outbuff);
    frfree(p_module_mng->p_st_l7_module->p_module_name);
    frfree(p_module_mng->p_st_l7_module->p_version);
    frfree(p_module_mng->p_st_l7_module);
    frfree(p_module_mng);
    frfree(p_st_node);
    frfree(p_st_proto_pri_node_data);
    return;

}


int add_suite___list_node_pri_show(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frproto_mng __list_node_pri_show()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
//    CU_add_test(pSuite, "case2", __case2);
//    CU_add_test(pSuite, "case3", __case3);
//    CU_add_test(pSuite, "case4", __case4);
//    CU_add_test(pSuite, "case5", __case5);

    return FR_SUCC;
}
